package bpd;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import bpd.test.RobotTestBed;
import robocode.BattleResults;
import robocode.control.events.BattleCompletedEvent;

/**
 * Illustrates JUnit testing of the Robocode robot PanzerBot. This test simply verifies that this
 * robot will beat another robot no less than ninety-percent of the time.
 * 
 * @author BJ Peter DeLaCruz
 * @version 1.0
 */
public abstract class PanzerBotVersus extends RobotTestBed {

  /**
   * Specifies the robots to be used in this test case. This method needs to be overwritten to
   * specify one or more robots.
   * 
   * @return A comma-delimited list of robots in this match
   */
  @Override
  public abstract String getRobotNames();
  
  /**
   * This test runs for twenty rounds.
   * 
   * @return The number of rounds in this test 
   */
  @Override
  public int getNumRounds() {
    return 20;
  }
  
  /**
   * Asserts that PanzerBot wins no less than ninety-percent of the time against another robot.
   * 
   * @param event Details about the completed battle
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    
    // Return the results in order of getRobotNames.
    BattleResults[] results = event.getIndexedResults();
    
    // Sanity check that results[1] is PanzerBot (not strictly necessary, but illustrative)
    assertEquals("Check results[1]", results[1].getTeamLeaderName(), "bpd.PanzerBot");
    
    // Check to make sure PanzerBot wins no less than 90% of the time. If PanzerBot wins less than
    // 90% of the time, then it will be time to upgrade the robot with better movement, tracking,
    // and firing mechanisms.
    assertTrue("Check PanzerBot winner", (results[1].getFirsts() >= getNumRounds() * 0.9));
    
  }
  
  /**
   * Returns false, thus making the robots in this test case always start at a random position each
   * time.
   * 
   * @return False if the battle will not be deterministic, true otherwise
   */
  @Override
  public boolean isDeterministic() {
    return false;
  }
  
}
